/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Arrays;

/**
 *
 * @author root
 */
public class ExtensionFilter implements FileFilter {

    private ArrayList<String> extensoes = new ArrayList<String>();

    public ExtensionFilter(String... exts) {
        this.extensoes.addAll(Arrays.asList(exts));
        for (int i = 0; i < extensoes.size(); i++) {
            this.extensoes.set(i, extensoes.get(i).toLowerCase());
        }
    }

    public boolean accept(File f) {
        if (extensoes.contains("*")) {
            return true;
        } else if (f.getName().contains(".")) {
            int iponto = 0;
            iponto = f.getName().lastIndexOf(".");
            String ext = f.getName().substring(iponto + 1).toLowerCase();
            return extensoes.contains(ext);
        } else {
            return extensoes.contains("");
        }
    }
}
